manual nix upgrade

2024-12-15 · 1 min read

(For multi-user Linux install)

By default, sudo nix upgrade-nix gets the new nix version from your nixpkgs flake registry entry (?), which should work for most people. If you need to install a specific nix version:

Take a look at the current system default profile:

$ nix profile history --profile /nix/var/nix/profiles/default
Version 1 (2024-08-03):
  nix: ∅ -> 2.18.5
  nss-cacert: ∅ -> 3.83

Version 2 (2024-11-03) <- 1: # <<< this is our current version
  nix: 2.18.5 -> 2.24.9

$ nix profile list --profile /nix/var/nix/profiles/default
Name:               nix
Store paths:        /nix/store/2nhrwv91g6ycpyxvhmvc0xs8p92wp4bk-nix-2.24.9

Name:               nss-cacert
Store paths:        /nix/store/ba4f8msp39cfvfpw3m7fsalb4psw347z-nss-cacert-3.83

Install the new nix version:

$ cd ~/dev/dotfiles
$ nix eval -f . _dbg.systemPkgs.x86_64-linux.nixVersions.latest.version
"nix-2.28.3"

# remove old version
$ sudo $(which nix) profile remove --profile /nix/var/nix/profiles/default nix

# install new version
$ sudo $(which nix) profile install --profile /nix/var/nix/profiles/default \
    -f . _dbg.systemPkgs.x86_64-linux.nixVersions.latest

# update CA certs?
$ sudo $(which nix) profile remove --profile /nix/var/nix/profiles/default nss-cacert
$ sudo $(which nix) profile install --profile /nix/var/nix/profiles/default \
    -f . _dbg.systemPkgs.x86_64-linux.cacert

Reload the nix daemon:

$ sudo systemctl daemon-reload && sudo systemctl restart nix-daemon

Sanity check:

$ nix --version
nix (Nix) 2.28.3

$ nix store info
Store URL: daemon
Version: 2.28.3
Trusted: 0

If something goes horribly wrong, you can always rollback:

$ sudo $(which nix) profile rollback --profile /nix/var/nix/profiles/default

In fact, you'll probably want to rollback before your next "normal" sudo nix upgrade-nix.